package profileactivity;


import java.util.List;

import profileactivity.UserProfileBaseAdapter.UserProfileViewHolder;

import com.ronipl.createtabs.R;
import com.ronipl.createtabs.R.id;
import com.ronipl.createtabs.R.layout;
import com.ronipl.createtabs.R.menu;
import com.ronipl.createtabs.model.valueobjects.IUserProfileActionListItem;
import com.ronipl.createtabs.utilities.dummy.DummyUserProfileList;


import android.app.Activity;
import android.content.Context;
import android.graphics.Typeface;

import android.os.Bundle;

import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;


public class AccountProfileActivity extends Activity {
	
	ListView list;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_account_profile);
		
		list = (ListView)findViewById(R.id.account_profile_listView);
		list.setAdapter(new UserProfileBaseAdapter(this));
	}
	


	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.account_profile, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}

class UserProfileBaseAdapter extends BaseAdapter{
	
	List<IUserProfileActionListItem>list;

	Context context;
	
	public UserProfileBaseAdapter(AccountProfileActivity accountProfileActivity){
		
		context = (Context)accountProfileActivity.getApplicationContext();
		list = DummyUserProfileList.getDummyUserProfileList();
	}

	@Override
	public int getCount() {
		
		return list.size();
	}

	@Override
	public Object getItem(int pos) {
		
		return list.get(pos);
	}

	@Override
	public long getItemId(int pos) {
		
		return pos;
	}
	
	class UserProfileViewHolder {
		
		TextView username;
		TextView position;
		TextView department;
		TextView datehired;
		TextView mobilenumber;
		TextView email;
		
		public UserProfileViewHolder(View v){
			
			username = (TextView)v.findViewById(R.id.username);
			position = (TextView)v.findViewById(R.id.position);
			department = (TextView)v.findViewById(R.id.department);
			datehired = (TextView)v.findViewById(R.id.date_hired);
			mobilenumber = (TextView)v.findViewById(R.id.mobile_number);
			email = (TextView)v.findViewById(R.id.email);
			
		}
		
		
		
	}
	

	@Override
	public View getView(int pos, View ConvertView, ViewGroup parent) {
		
		View row = ConvertView;
		UserProfileViewHolder holder = null;
		
		if(row == null){
			
			LayoutInflater inflater =(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			row = inflater.inflate(R.layout.account_profile_list, parent, false);
			holder = new UserProfileViewHolder(row);
			row.setTag(holder);
		}
		else 
		{
		
			holder = (UserProfileViewHolder)row.getTag();	
			
		}
		
		IUserProfileActionListItem data = list.get(pos);
		
		holder.username.setText(data.getHeader());
		holder.position.setText(data.getPos());
		holder.department.setText(data.getDept());
		holder.datehired.setText(data.getDateHired());
		holder.mobilenumber.setText(data.getMobileNumber());
		holder.email.setText(data.getEmail());
		
		
		
		Typeface cus_font = Typeface.createFromAsset(context.getAssets(), "fonts/opensansregular.ttf");
		holder.username.setTypeface(cus_font);
		holder.position.setTypeface(cus_font);
		holder.department.setTypeface(cus_font);
		holder.datehired.setTypeface(cus_font);
		holder.mobilenumber.setTypeface(cus_font);
		holder.email.setTypeface(cus_font);
		
		return row;
	}
	
}





